﻿Imports DTO
Imports System.Data.SqlClient
Public Class CTDICHVUDAO
    Private ketnoi As New DAO.connect()
    Public Function loadctdv() As DataTable
        ketnoi.OpenConnection()
        Dim dtnv As New DataTable()
        Dim chuoi As String = "select * from CTDICHVU"
        dtnv = ketnoi.getDataTable(chuoi)
        ketnoi.CloseConnection()
        Return dtnv
    End Function
    Private Function Sqlcommand_THEM(ByVal MACHITIETDICHVU As Integer, ByVal MADICHVU As Integer, ByVal DONGIADICHVU As Double, ByVal MATIECCUOI As Integer) As Integer
        ketnoi.OpenConnection()
        Dim i As Integer = 0

        Dim sqlcmd As New SqlCommand("Stor_THEM_CTDICHVU", ketnoi.getConnection)
        sqlcmd.CommandType = CommandType.StoredProcedure
        'sqlcmd.Parameters.Add("@mode", SqlDbType.Int).Value = mode;
        sqlcmd.Parameters.Add("@MACHITIETDICHVU", SqlDbType.Int).Value = MACHITIETDICHVU
        sqlcmd.Parameters.Add("@MADICHVU", SqlDbType.Int).Value = MADICHVU
        sqlcmd.Parameters.Add("@DONGIADICHVU", SqlDbType.Float).Value = DONGIADICHVU
        sqlcmd.Parameters.Add("@MATIECCUOI", SqlDbType.Int).Value = MATIECCUOI



        i = sqlcmd.ExecuteNonQuery()
        ketnoi.CloseConnection()
        Return i
    End Function
    Public Function them_CTDICHVU(ByVal dto As CTDICHVUDTO)
        ketnoi.OpenConnection()
        'Dim dto As New LOAISANHDTO()
        If Sqlcommand_THEM(dto.MACHITIETDICHVU, dto.MADICHVU, dto.DONGIADICHVU, dto.MATIECCUOI) <> 0 Then
            ketnoi.CloseConnection()
            Return True
        End If
        ketnoi.CloseConnection()
        Return False
    End Function

    Private Function Sqlcommand_capnhat(ByVal MACHITIETDICHVU As Integer, ByVal MADICHVU As Integer, ByVal DONGIADICHVU As Double, ByVal MATIECCUOI As Integer) As Integer
        ketnoi.OpenConnection()
        Dim i As Integer = 0

        Dim sqlcmd As New SqlCommand("Stor_CAPNHAT_CTDICHVU", ketnoi.getConnection)
        sqlcmd.CommandType = CommandType.StoredProcedure
        'sqlcmd.Parameters.Add("@mode", SqlDbType.Int).Value = mode;
        sqlcmd.Parameters.Add("@MACHITIETDICHVU", SqlDbType.Int).Value = MACHITIETDICHVU
        sqlcmd.Parameters.Add("@MADICHVU", SqlDbType.Int).Value = MADICHVU
        sqlcmd.Parameters.Add("@DONGIADICHVU", SqlDbType.Float).Value = DONGIADICHVU
        sqlcmd.Parameters.Add("@MATIECCUOI", SqlDbType.Int).Value = MATIECCUOI


        i = sqlcmd.ExecuteNonQuery()
        ketnoi.CloseConnection()
        Return i
    End Function
    Public Function capnhat_ctdichvu(ByVal dto As CTDICHVUDTO) As Boolean
        ketnoi.OpenConnection()
        If Sqlcommand_capnhat(dto.MACHITIETDICHVU, dto.MADICHVU, dto.DONGIADICHVU, dto.MATIECCUOI) <> 0 Then
            ketnoi.CloseConnection()
            Return True
        End If
        ketnoi.CloseConnection()
        Return False

    End Function

    Private Function Sqlcommand_XOA(ByVal MACHITIETDICHVU As Integer) As Integer
        ketnoi.OpenConnection()
        Dim i As Integer = 0

        Dim sqlcmd As New SqlCommand("Stor_XOA_CTDICHVU", ketnoi.getConnection)
        sqlcmd.CommandType = CommandType.StoredProcedure
        sqlcmd.Parameters.Add("@MACHITIETDICHVU", SqlDbType.Int).Value = MACHITIETDICHVU

        i = sqlcmd.ExecuteNonQuery()
        ketnoi.CloseConnection()
        Return i
    End Function
    Public Function xoa_CTDICHVU(ByVal dto As CTDICHVUDTO) As Boolean
        ketnoi.OpenConnection()
        If Sqlcommand_XOA(dto.MACHITIETDICHVU) <> 0 Then
            ketnoi.CloseConnection()
            Return True
        End If
        ketnoi.CloseConnection()
        Return False

    End Function

End Class
